package com.health.config;

import com.health.filter.CrossDomainFilter;
import com.health.filter.LoginFilter;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import javax.annotation.Resource;

/**
 * 过滤器优先级配置
 */
@Configuration
public class FilterConfig {

    @Resource
    private LoginFilter loginFilter;

    @Resource
    private CrossDomainFilter crossDomainFilter;

    @Bean
    public FilterRegistrationBean<CrossDomainFilter> enCodeFilterSet(){
        FilterRegistrationBean<CrossDomainFilter> filterRegistrationBean=new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(crossDomainFilter);
        filterRegistrationBean.addUrlPatterns("/*");
        filterRegistrationBean.setOrder(1); //order的数值越小 则优先级越高
        return filterRegistrationBean;
    }

    @Bean
    public FilterRegistrationBean<LoginFilter> loginFilterSet(){
        FilterRegistrationBean<LoginFilter> filterRegistrationBean=new FilterRegistrationBean<>();
        filterRegistrationBean.setFilter(loginFilter);
        filterRegistrationBean.addUrlPatterns("/checkItem123/*");
        filterRegistrationBean.setOrder(2);
        return filterRegistrationBean;
    }
}
